<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<table width="670" border="0" cellspacing="0" cellpadding="0"  id="tableformDangNhap">
    <tr align="center" valign="middle" bgcolor="#FF0000">
        <td  bgcolor="#FF0000" height="30" colspan="2" class="menu1">SẢN PHẨM</td>
    </tr>
    <tr>
        <td id="tdformDangNhap" width="70%">
            Trang 
            <c:forEach var="i" begin="1" end="${soTrang}"
                       step="1" >
                <a style="color:#00C" href="SanPhamAll.do?&trang=${i}&soLuongSanPhamTrenTrang=${soLuongSanPhamTrenTrang}">${i}</a>
                <c:if test="${i < soTrang}" >
                    |
                </c:if>
            </c:forEach>

        </td>
        <td  width="30%" align="right">
            <form name="frmSoSanPhamTrenTrang" action="SanPhamAll.do" method="get">
                <label for="soLuongSanPhamTrenTrang">Số lượng</label>
                <select name="soLuongSanPhamTrenTrang" onchange="submit()">
                    <c:forEach var="i" begin="1" end="5">
                        <option 
                            <c:if test="${i*3 == soLuongSanPhamTrenTrang}" >
                                selected="selected"
                            </c:if>
                            value="${i*3}">${i*3}</option>
                    </c:forEach>
                    <option
                        <c:if test="${soLuongSanPhamTrenTrang}==-1" >
                            selected="selected"
                        </c:if>
                        value="-1">Tất cả</option>
                </select>
            </form>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <table width="100%" border="0" cellspacing="0" cellpadding="5">
                <c:choose>
                    <c:when test="${dssp.size()%3 ==0}" >
                        <c:set var="so_hang" value="${dssp.size()/3}"/>
                    </c:when>
                    <c:when test="${dssp.size()%3 !=0}" >
                        <c:set var="so_hang" value="${dssp.size()/3+1}"/>
                    </c:when>
                </c:choose>
                <c:forEach var="i" begin="0" end="${so_hang-1}" step="1">

                    <tr>
                        <c:set var="vtr_ketthuc" value="${i*3+3}"/>
                        <c:if test="${dssp.size()<i*3+3}">
                            <c:set var="vtr_ketthuc" value="${dssp.size()}"/>
                        </c:if>
                        <c:forEach var="t" begin="${i*3}" end="${vtr_ketthuc-1}" step="1">
                            <c:set var="sp" value="${dssp.get(t)}"/>
                            <!--Bắt đầu 1 hàng-->
                            <td class="sanpham_cell" width="33%" align="center" valign="top">
                                <table border="0" width="100%">
                                    <tr>
                                        <td class="tieude_cell" height="40px">
                                            <b><a href="index.jsp?MainContent=ChiTietSanPham&MaSanPham=${sp.maSanPham}" title="Click xem chi tiết sản phẩm" class="sanpham_link">
                                                    ${sp.tenSanPham}</a></b>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="hinh_cell">
                                            <a href="index.jsp?MainContent=ChiTietSanPham&MaSanPham=${sp.maSanPham}">
                                                <img src="${sp.hinhAnh}" width="150" height="125" alt="Click để xem chi tiết"
                                                     />
                                            </a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="center" clas="gia_cell">
                                            <fmt:formatNumber type="currency" value="${sp.donGia}" />

                                        </td>
                                    </tr>
                                    <tr >
                                        <td  style="padding-left: 65px;">
                                            <c:forEach var="p" begin="1" end="${sp.diemDanhGia}" step="1">
                                                <div id="star-${p}" class="rating-on"></div>
                                            </c:forEach>
                                            <c:forEach var="p" begin="${sp.diemDanhGia}" end="4" step="1">
                                                <div id="star-${p}" class="rating-off"></div>
                                            </c:forEach>

                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="center" clas="gia_cell" style="background-color:#cad9ed">
                                            <a href="GioHang.do?Action=DatMua&MaSanPham=${sp.maSanPham}&SoLuong=1" style="color:#0762A2;"><input  type="button" value="" style="background-image:url(images/AddToCart_new.jpg); background-repeat:no-repeat; width:150px; height:30px;" /></a>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <!--Những o ko co san pham-->

                        </c:forEach>
                        <c:forEach var="t" begin="${vtr_ketthuc}" end="${i*3+3}" step="1">

                            <td class="sanpham_cell" width="33%" align="center" valign="top">&nbsp;</td>
                        </c:forEach>
                        <!--Kết thúc 1 hàng-->
                    </tr>
                </c:forEach>
            </table>

        </td>
    </tr>              
</table>
